package com.yang.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

/**
 * @author yangjiming
 * @create 2021-03-26 18:38
 */
public class InsertMysql {
    public static void main(String[] args) throws Exception{
        //加载驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接
        String url="jdbc:mysql://master:3306/shujia";
        String username="root";
        String password="123456";
        Connection conn = DriverManager.getConnection(url,username,password);
        //获取执行器
        Statement statement = conn.createStatement();
        //获取结果并解析
        String name="test1";
        int age=20;
        String sex="0";
        //inster into student(name,age,sex) values('name','age','sex')
        String sql = "insert into student(name,age,sex) values('"+name+"',"+age+",'"+sex+"')";
        System.out.println(sql);
        int i = statement.executeUpdate(sql);
        System.out.println(i);
        //关闭连接
        statement.close();
        conn.close();
    }
}
